define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p>是否确认通过提货申请？</p>",
        text4Btn: ["确定", "取消"],
        class4Btn: ["", "line"]
    });

    var _vm = Init.initVue({
        data : {
            list : [],
            name : '',
            no : '',
            status : '',
            cur : 1,
            all : 0,
            search : false,
            remark : '',
            show : false,
            id : null
        },
        methods: {
            reSearch : function() {
                this.search = true;
                this.getData(1);
            },
            reset : function() {
                this.search = false;
                this.name = '';
                this.no = '';
                this.status = '';
            },
            getData : function(n) {
                var obj = {
                    page: n,
                    num: 10,
                    name: this.name,
                    user_id: this.no,
                    status: this.status
                };

                METHOD.loading.show();
                METHOD.ajax("tradetake/list",obj).done(function(json){
                    METHOD.loading.hide();
                    _vm.list = json.data;
                    _vm.all = json.page.pages;
                }).fail(function(){
                    METHOD.loading.hide();
                });
            },
            operate : function(id,type) {

                var obj = {};

                if (type == 1) {
                    _Dialog.changeCfg({
                        content : "<p>是否确认通过提货申请？</p>",
                    });
                    obj.status = 2;
                } else if (type == 2) {
                    obj.status = 4;
                }

                _Dialog.showUI(function(i) {
                    obj.take_id = id;

                    if (i == 0) {
                        _vm.postData(obj);
                    }
                    this.hideUI();
                });
            },
            reject : function(id) {
                var obj = {};

                if (id) {
                    this.show = true;
                    this.id = id;
                } else {
                    if (!_vm.remark) {
                        METHOD.alert("请输入驳回理由");
                        return;
                    } else {
                        obj.take_id = this.id;
                        obj.status = 3;
                        obj.remark = _vm.remark;
                        this.postData(obj);
                    }
                }
            },
            cancel : function() {
                this.show = false;
                this.id = null;
                this.remark = '';
            },
            postData: function(obj) {
                METHOD.loading.show();
                METHOD.ajax("tradetake/check", {data:JSON.stringify(obj)}, {type:"post"}).done(function(json){
                    METHOD.loading.hide();
                    if (_vm.show) { _vm.cancel(); }
                    _vm.getData(1);
                }).fail(function(){
                    METHOD.loading.hide();
                });
            }
        }
    });

    _vm.getData(1);

});

